package com.waypolice.manager.service.impl;

import com.waypolice.base.BaseServiceImpl;
import com.waypolice.manager.service.UpmsFileNumService;
import com.waypolice.mapper.UpmsFileNumMapper;
import com.waypolice.pojo.UpmsFileNum;
import com.waypolice.pojo.UpmsFileNumExample;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

/**
* UpmsFileNumService实现
*Created by lzh on 2019/3/12
*/
@Service
public class UpmsFileNumServiceImpl extends BaseServiceImpl<UpmsFileNumMapper, UpmsFileNum, UpmsFileNumExample> implements UpmsFileNumService {

    private static final Logger LOGGER = LoggerFactory.getLogger(UpmsFileNumServiceImpl.class);

    @Autowired
    UpmsFileNumMapper upmsFileNumMapper;
/**
*查询案卷号长度
*zhangruyi
*/
    @Override
    public UpmsFileNum getFieldsLength(String code) {
        UpmsFileNumExample upmsFileNumExample = new UpmsFileNumExample();
        UpmsFileNumExample.Criteria criteria = upmsFileNumExample.createCriteria();
        criteria.andCodeEqualTo(code);
        //criteria.andPkCodeEqualTo("tradition");//传统案卷类型
        upmsFileNumExample.setOrderByClause("\"FILE_ID\" ASC");//以id升序查询
        List<UpmsFileNum> upmsFileNums = upmsFileNumMapper.selectByExample(upmsFileNumExample);
        if (upmsFileNums.size() == 0){
            return  null;
        }else if (upmsFileNums.size() == 1){
            return upmsFileNums.get(0);
        }else {
            return upmsFileNums.get(upmsFileNums.size()-1);
        }
    }
}